package com.lz.demo2;

import java.util.Random;
import java.util.Scanner;

/**
 * @ClassName TestShape
 * @Description 测试
 * @Author 2214361854
 * @Date 2022/5/28 14:19
 * @Version 1.0
 */
public class TestShape {
    public static void main(String[] args) {
        System.out.println("按回车继续");
        System.out.println("----------------");
        while (true) {
            int r = new Random().nextInt(4) + 1;
            switch (r) {
                case 1:
                    f(new Line());
                    break;
                case 2:
                    f(new Square());
                    break;
                case 3:
                    f(new Circle());
                    break;
            }
        }
    }

    /*
     * Shape
     *   |- Line
     *   |- Square
     *   |- Circle
     */
    static void f(Shape s) {
        s.draw();
        if(s instanceof Line) {
            //向下转型成Line类型，才能调用它特有的方法
            Line line = (Line) s;
            line.length();
        }
        new Scanner(System.in).nextLine();
        s.clear();
    }
}
